package Excel;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class ExcelTest {
    public static void main(String[] args) {
    String neme = "D:/工作文档/地下水项目/文档/读取文件测试.xlsx";
    }
    public static void ExcelTest(String FileSite){
        Workbook workbook = null;
        File file = new File(FileSite);
        if (!file.exists()){
            System.out.println("文件不存在");
        }
        //获取后缀名
        String suffix = FileSite.substring(FileSite.lastIndexOf("."));
        try {
            InputStream inputStream = new FileInputStream(file);
            if ("xls".equals(suffix)){
                workbook = new HSSFWorkbook(inputStream);
            }else if ("xlsx".equals(suffix)){
                workbook = new XSSFWorkbook(inputStream);
            }
        }catch (Exception e ){
            e.fillInStackTrace();
            System.out.println(e.fillInStackTrace().toString());
        }


    }
}
